library(R.matlab)
abd_mFile <- as.list(paste(1:20, "/ABD.mat", sep = ""))
tho_mFile <- as.list(paste(1:20, "/THO.mat", sep = ""))
cflow_mFile <- as.list(paste(1:20, "/CFlow.mat", sep = ""))
stage_mFile <- as.list(paste(1:20, "/STAGE.mat", sep = ""))
abd <- lapply(abd_mFile, readMat)
tho <- lapply(tho_mFile, readMat)
cflow <- lapply(cflow_mFile, readMat)
stage <- lapply(stage_mFile, readMat)
Let’s take a quick look at the ABD, THO, Flow time series (from 5 min to 15 min) to get an idea about across patients variation
t <- 301:900
Vars <- c("ABD", "THO", "FLOW")
cols <- c("blue", "green", "red")
for (i in 1:20){
plot(t, cflow[[i]]$CFlow[t*100],
type = "l", xlab = "Time (sec)",
ylab = "Flow", las = 1,
col = "red", ylim = range(cflow[[i]]$CFlow[t*100], abd[[i]]$ABD[t*100],
tho[[i]]$THO[t*100]))
lines(t, abd[[i]]$ABD[t*100],
col = "blue", lwd = 0.75)
lines(t, tho[[i]]$THO[t*100],
col = "green", lwd = 0.75)
legend("bottomright", legend = Vars, col = cols, lty = 1, bty = "n",
cex = 0.6)
}
for (i in 1:20) plot(t/60, stage[[i]]$STAGE[t], ylim = c(10.5, 16.5),
xlab = "Time (min)", ylab = "Sleep stage", type = "l", las = 1)
lm <- array(dim = c(20, 2))
for (i in 1:20){
# center
z0 <- cflow[[i]]$CFlow[t*100]
x0 <- abd[[i]]$ABD[t*100]
y0 <- tho[[i]]$THO[t*100]
z <- z0 - median(z0); y <- y0 - median(y0); x <- x0 - median(x0)
lm[i,] = lm(z ~ x + y)$coefficients[2:3]
}
m <- lm(z ~ x + y)
plot(1:20, lm[, 1], col = "blue", pch = 16, ylim = range(lm),
ylab = "Coefficients", xlab = "Patient id", las = 1)
points(1:20, lm[, 2], col = "green", pch = 16)
abline(h = 0, lty = 2, col = "gray")